import Line from '../utils/Graph/Line.js';
/**
 * Tape Measure based on Graph.Line.
 * @author wangdasong
 * @date 2022.01.30
 */

class TapeMeasure extends Line {
    constructor({ pos } = {}) {
        super(...arguments);
        this.name = 'TAPEMEASURE';
        if (!this.points || !this.points.length) this.points = [pos, pos];
    }
    draw(ctx) {
        if (ctx) this.ctx = ctx;

        this.ctx.save();
        this.ctx.lineWidth = this.lineWidth;
        this.ctx.strokeStyle = this.strokeStyle;
        this.ctx.beginPath();
        this.points.forEach((p, i) => {
            let y = this.isReverse ? -p.y : p.y;
            if (i == 0) {
                this.ctx.moveTo(p.x, y);
            } else {
                this.ctx.lineTo(p.x, y);
            }
        });
        this.ctx.closePath();
        this.ctx.stroke();

        // labels
        // this.labels = 'test';
        let textFontSize = this.lineWidth * 30;
        this.ctx.font = textFontSize + 'px Arial';
        this.ctx.fillStyle = 'rgba(0, 0, 0, 0.8)';
        this.ctx.textAlign = 'center';
        this.ctx.textBaseline = 'bottom';
        this.ctx.fillText(this.labels || '0m', this.x, -this.y);

        this.ctx.restore();
        // console.log('Line.draw: ', this, JSON.stringify(this.points));
    }
}
export default TapeMeasure;
